import 'dart:ffi';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'bindings.dart';
import 'leaf_rust_platform_interface.dart';

/// An implementation of [LeafRustPlatform] that uses method channels.
class MethodChannelLeafRust extends LeafRustPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final methodChannel = const MethodChannel('leaf_rust');

   static final LeafBindings _bindings = LeafBindings(MethodChannelLeafRust._loadLibrary());

  static DynamicLibrary _loadLibrary() {
    return DynamicLibrary.process();
  }

  @override
  Future<String?> getPlatformVersion() async {
    final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
    return version;
  }

  @override
  Future<int?> leafRun(int rtId, String configPath) async {
    final result = await methodChannel.invokeMethod<int>('leaf_run', {
      "rtId": rtId,
      "configPath": configPath,
    });
    return result;
  }
}
